<template>
	<view class="wrap">
		<view class="search cu-bar">
			<u-search  v-model="barCode" :focus="focus" @confirm="search" @custom="search" @search="search" placeholder="扫一扫"  :show-action="false"></u-search>
			<view class="action" @click="toScan">
				<text class="cuIcon-scan" style="font-size: 56rpx;"></text>
			</view>
		</view>
		<u-form class="form bg-white" :model="model" ref="uForm" label-position="left">
			<u-form-item label="物料编码:" prop="cinvcode" label-width="180" :label-style="{'font-weight':'bold'}">
				<view>{{model.basInv.cinvcode}}</view>
			</u-form-item>
			<u-form-item label="物料代码:" prop="cinvcode" label-width="180" :label-style="{'font-weight':'bold'}">
				<view>{{model.basInv.cinvaddcode}}</view>
			</u-form-item>
			<u-form-item label="物料名称:" prop="cinvcode" label-width="180" :label-style="{'font-weight':'bold'}">
				<view>{{model.basInv.cinvname}}</view>
			</u-form-item>
			<u-form-item label="仓库:" prop="cwhcode" label-width="180" :label-style="{'font-weight':'bold'}">
				<view>{{model.cwhcode}}</view>
			</u-form-item>
			<u-form-item label="批次:" prop="pcno" label-width="180" :label-style="{'font-weight':'bold'}">
				<view>{{model.pcno}}</view>
			</u-form-item>
			<u-form-item label="数量:" prop="qty" label-width="180" :label-style="{'font-weight':'bold'}">
				<view>{{model.qty}}</view>
			</u-form-item>
		</u-form>
		<view class="footer">
			<view class="confrim-btn padding padding-bottom-sm flex bg-white">
				<u-button  type="primary" class="btn" style="width: 100%;" @click="submit">提交</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				focus: true,
				barCode:'',
				model: {
					basInv:{},
				},
			}
		},
		onLoad(params) {
			
		},
		watch: {
		
		},
		onShow() {},
		onReady() {},
		methods: {
			toScan(){
				uni.scanCode({ 
					onlyFromCamera: true,
					success: function(res) {
						this.barCode = res.result;
						this.search();
					}.bind(this)
				});
			},
			search(){
				this.$u.api.asdApi.getXppData({barCode:this.barCode}).then(res => {
					this.barCode = '';
					this.model = res.data;
				})
			},
			submit() {
				var data = {
					cinvcode: this.model.basInv.cinvcode,
				    cwhcode: this.model.cwhcode,
				    cbatch: this.model.pcno,
				    iqty: this.model.qty,
				    xppNo: this.model.djno,
					retrace: this.model.djno,
				}
				
				this.$u.api.asdApi.saveTl(data).then(res => {
					uni.showModal({
						title: '提示',
						content: res.message,
						showCancel: false,
						success: (res) => {}
					});
					if(res.result == 'true'){
						uni.navigateBack({
							delta: 1,
						})
					}
				})
			},
		}
	}
</script>
<style>
	@import '../asd.css';
</style>
